<?php
session_start();
$username = isset($_POST['username'])?trim($_POST['username']):'';
$password = isset($_POST['password'])?trim($_POST['password']):'';

//$arr1 = ['username'=>$username,'password'=>$password];

$sql = file('database.sql');
//['admin,admin888','zxj,zxj888']
foreach ($sql as $v){
    $database[] = explode(',',trim($v));
}
//[['admin','admin888'],['zxj','zxj888']]

foreach ($database as $v){
    if($v[0]==$username&&$v[1]==$password){
        $res = ['status'=>1,'msg'=>'登陆成功！'];
        $_SESSION['user'] = $username;
        echo json_encode($res);
        exit;
    }
}
    $res = ['status'=>0,'msg'=>'账号或密码错误'];
    echo json_encode($res);